package com.tengju.bff.interfaces.manage.crm.activity.vo;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.validation.constraints.NotNull;
import java.util.Comparator;
import java.util.List;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@ApiModel(value = "ActivityDetailVO", description = "活动明细")
public class ActivityDetailVO {

    @ApiModelProperty(value = "活动名称")
    String activityName;

    @ApiModelProperty(value = "活动时间")
    String activityTime;

    @ApiModelProperty(value = "活动类型")
    String activityType;

    @ApiModelProperty(value = "会员类型")
    String customerType;

    @ApiModelProperty(value = "活动目标")
    String activityTarget;

    @ApiModelProperty(value = "活动预热时间")
    String warmupTime;

    @ApiModelProperty(value = "活动冻结时间")
    String freezeTime;

    @ApiModelProperty(value = "VTN下单用户")
    LimitCustomer limitCustomer;

    @ApiModelProperty(value = "活动商品范围")
    LimitGoods limitGoods;


    @ApiModelProperty(value = "活动目标配置")
    List<LimitRule> limitRules;

    public void setLimitRules(List<LimitRule> limitRules) {
        this.limitRules = limitRules;
        this.limitRules.sort(Comparator.comparing(LimitRule::getRuleSubjectId).reversed()
                .thenComparing(LimitRule::getDate));
    }

    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    public static class LimitCustomer {

        @ApiModelProperty(value = "定向")
        String limitRange = "VTN等级";

        @ApiModelProperty(value = "等级列表")
        List<String> limitCustomerLevel;

    }

    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    public static class LimitGoods {

        @ApiModelProperty(value = "维度类型")
        String goodsType;

        @ApiModelProperty(value = "定向")
        String limitRange;

        @ApiModelProperty(value = "商品列表")
        List<Goods> goods;
    }

    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    public static class LimitRule {

        @ApiModelProperty(value = "考核指标")
        String targetType;


        @NotNull(message = "活动总目标不能为空")
        @ApiModelProperty(value = "活动总目标")
        String targetTotalAmount;

        @ApiModelProperty(value = "定向目标ID")
        String ruleId;

        @NotNull(message = "活动定向实体不能为空")
        @ApiModelProperty(value = "定向实体ID")
        String ruleSubjectId;

        @ApiModelProperty(value = "定向类型")
        String ruleType;

        @ApiModelProperty(value = "参考周期开始")
        String referStartDate;

        @ApiModelProperty(value = "参考周期结束")
        String referEndDate;

        @ApiModelProperty(value = "对标配置")
        List<Goods> referGoods;

        @NotNull(message = "活动定向日期不能为空")
        @ApiModelProperty(value = "日期")
        String date;

        @ApiModelProperty(value = "日目标")
        String targetAmount;
    }


    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    public static class Goods {
        @ApiModelProperty(value = "商品ID")
        String id;

        @ApiModelProperty(value = "商品名称")
        String name;
    }
}
